<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .redBg{
            background: red;
        }
    </style>
</head>
<body>
<div id="app"></div>
<!--react的核心库-->
<script type="text/javascript" src="../utils/react.development.js"></script>
<!--react的扩展库，专门用于操作DOM-->
<script type="text/javascript" src="../utils/react-dom.development.js"></script>
<!--引入babel，用于解析jsx语法为原生js语法-->
<script type="text/javascript" src="../utils/babel.min.js"></script>

<script type="text/babel">
    // 获取组件的四种方式
    class MyComponent extends React.Component{
        input4=React.createRef()
        // 使用refs
        GetName=()=> {
            const {input1} = this.refs
            console.log(input1.value)
        }
        //回调ref
        GetAge=()=>{
            const {input3}=this
            console.log(input3.value)
        }
        //createRfe
        GetInputCreate=()=>{
            console.log(this.input4)
        }
        //如果需要获取值的dom 就是触发事件的dom可以直接获取
        getInputTarget(e){
            console.log(e.target.value)
        }
        render(){
            return (
                <form action="reactBase/getComDom?tn=25017023_17_dg">
                    <input ref='input1' type="text" placeholder="请输入姓名" name="name" id="name" onBlur={this.GetName}/><br/>
                    <input ref={(currentNode)=>this.input3=currentNode} type="text"  placeholder="请输入年龄" name="age" id="age" onBlur={this.GetAge}/><br/>
                    <input ref={this.input4} type="text" onBlur={this.GetInputCreate} name="name" id="name"/>
                    <input type="text" onBlur={this.getInputTarget} name="sex" id="sex"/>
                    <button>提交</button>
                </form>
            )
        }
    }
    ReactDOM.render(<MyComponent/>,document.querySelector('#app'))
</script>
</body>
</html>
